package com.ziyun.erp.web.modules.freightBase.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.UserUtil;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.freightBase.entity.FreightBaseEntity;
import com.ziyun.erp.modules.freightBase.service.FreightBaseService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 运费基础数据
 *
 * @author zh
 * @email 
 * @date 2018-12-26 09:04:55
 */
@RestController
@RequestMapping("freightBase/freightbase")
public class FreightBaseController {
    @Autowired
    private FreightBaseService freightBaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("freightBase:freightbase:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = freightBaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{baseId}")
    @RequiresPermissions("freightBase:freightbase:info")
    public R info(@PathVariable("baseId") Integer baseId){
        FreightBaseEntity freightBase = freightBaseService.selectById(baseId);

        return R.ok().put("freightBase", freightBase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("freightBase:freightbase:save")
    public R save(@RequestBody FreightBaseEntity freightBase){
        freightBaseService.insert(freightBase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("freightBase:freightbase:update")
    public R update(@RequestBody FreightBaseEntity freightBase){
        ValidatorUtils.validateEntity(freightBase);
        freightBaseService.updateAllColumnById(freightBase);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("freightBase:freightbase:delete")
    public R delete(@RequestBody Integer[] baseIds){
        freightBaseService.deleteBatchIds(Arrays.asList(baseIds));

        return R.ok();
    }

    @RequestMapping("/importExcel")
    public R importExcel(@RequestParam("file") MultipartFile multipartFile)  {
        freightBaseService.handleExcel(multipartFile,UserUtil.getCurrentUser().getUsername());
        return R.ok();
    }

}
